package com.mingke.db.Controller;

import cn.hutool.core.util.CharsetUtil;
import com.mingke.db.Entity.SchemaTableColumn;
import com.mingke.db.Service.SchemaService;
import com.mingke.db.Service.TestService;
import com.mingke.db.Utils.PropertiesReader;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    PropertiesReader propertiesReader;

    @Autowired
    SchemaService schemaService;

    @Autowired
    TestService testService;

    @GetMapping("generateCode")
    public String generateCode() throws FileNotFoundException {
        long startTime = System.currentTimeMillis();    //获取开始时间
        List<String> selectTables = schemaService.listTables(propertiesReader.selectSchema);
        //根据当前选中的数据表来生成对应的实体类
        for (String item : selectTables){
            List<SchemaTableColumn> columns = schemaService.listTableColumns(item);
            System.out.println("当前数据表："+item);
            testService.doGenerateCode(item, columns);
        }
        long endTime = System.currentTimeMillis();    //获取结束时间
        System.out.println("程序运行时间：" + (endTime - startTime) + "ms");    //输出程序运行时间
        return "hello";
    }
}
